package com.zzq.my.jetpacks.jectpackapp.ui.act

import android.util.Log
import androidx.databinding.ViewDataBinding
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.aisier.architecture.util.byteArrayOfInts
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.bean.ItemInfo
import com.zzq.my.jetpacks.jectpackapp.databinding.ActivityMmkvBinding
import com.zzq.my.jetpacks.util.MMKVUtils
import com.zzq.my.jetpacks.util.bindView

/**
 * 描述：MMKV 的基本用法
 * 作者：zhuangzeqin
 * 时间: 2022/1/18-17:04
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class MMKVActivity : BaseActivity(R.layout.activity_mmkv) {
    private val vb by viewBinding(ActivityMmkvBinding::bind)

    /**
     * 初始化数据
     */
    override fun initData() {
//        var binding = DataBindingUtil.inflate<ActivityMmkvBinding>(
//            LayoutInflater.from(mContext),
//            R.layout.activity_mmkv,
//            parent,
//            false
//        )
        val bindView = bindView<ViewDataBinding>(R.layout.activity_mmkv)
    }

    /**
     * 初始化操作
     */
    override fun initView() {

    }

    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {
        vb.stvMmkvPut.setOnClickListener {
            MMKVUtils.put("string","zhuangzeqin")//String
            MMKVUtils.put("int",33)//int
            MMKVUtils.put("long",13.00.toLong());//long
            MMKVUtils.put("boolean",true);//boolean
            MMKVUtils.put("float",14.00.toFloat());//float
            MMKVUtils.put("double",15.00.toDouble());//double
            val arr = byteArrayOfInts(0xA1, 0x2E, 0x38, 0xD4, 0x89, 0xC3)
            MMKVUtils.put("bytearray",arr)
            val itemInfo = ItemInfo("ybh")
            MMKVUtils.put("bean",itemInfo)
            val hashSetOf = hashSetOf("a", "b", "c","d","e")
            MMKVUtils.put("setString",hashSetOf)
        }
        vb.stvMmkvGet.setOnClickListener {
            val string = MMKVUtils.getString("string")
            val int = MMKVUtils.getInt("int")
            val long = MMKVUtils.getLong("long")
            val boolean = MMKVUtils.getBoolean("boolean")
            val float = MMKVUtils.getFloat("float")
            val double = MMKVUtils.getDouble("double")
            val bean = MMKVUtils.getParcelable<ItemInfo>("bean")

            val bytearray = MMKVUtils.getByteArray("bytearray")
            val setString = MMKVUtils.getStringSet("setString")
            Log.d(TAG, "eventOnClick: $string")
            Log.d(TAG, "eventOnClick: $int")
            Log.d(TAG, "eventOnClick: $long")
            Log.d(TAG, "eventOnClick: $boolean")
            Log.d(TAG, "eventOnClick: $float")
            Log.d(TAG, "eventOnClick: $double")
            Log.d(TAG, "eventOnClick: ${bean.toString()}")
            Log.d(TAG, "eventOnClick: $bytearray")
            Log.d(TAG, "eventOnClick: $setString")

            //疯 ！ 17:00:02
           // "(^\\w)[^@]*(@.*$)", "$1****$2"   这个正则 是邮箱脱敏只显示第一位后面都用*代替 我想要只显示前两位后面都用*代替

           // 疯 ！ 17:00:53
           // 目前效果是比如 490930685@qq.com 变成 4****@qq.com  我想要的是49***@qq.com

            val email  = "436990930685@qq.com"

            val buffer = StringBuffer(email)
            println(buffer.toString()) //输出490930685@qq.com
//            KLog.d(buffer.toString())

            buffer.replace(2, buffer.indexOf("@"), "****")
            println(buffer.toString()) //输出a23456
//            KLog.d(buffer.toString())


            val regex = "(^\\w{2})[^@]*(@.)"
            val regex1 = Regex(regex)
            println(regex1.replace(email,"$1****$2"))

//            KLog.d(regex1.replace(email,"$1****$2"))
//            buffer.replacea
//            String s = content . repLaceALL(regx, replacement: ” $1****$2");


        }

    }


}